package com.Apo1o.controller;

import com.Apo1o.bean.ext.ManagerHurdlesExt;
import com.Apo1o.response.Result;
import com.Apo1o.service.IFenceHouseService;
import com.Apo1o.service.IHurdlesExtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Auther: Apo1o.
 * @Date: 2023/11/1-11-01-13:59
 * @Description： com.Apo1o.controller
 */
@Api(tags = "栏圈管理模块")
@RestController
@RequestMapping("hurdle")
@RequiredArgsConstructor
public class HurdlesExtController {
    private    final IHurdlesExtService iHurdlesExtService;
    private  final IFenceHouseService iFenceHouseService;


    @GetMapping("queryAllMax")
    public Result findAllMax(){
        return Result.success(iHurdlesExtService.findAllMax());
    }
    @ApiOperation("分页多条件查询栏舍信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小", defaultValue = "10", required = true),
            @ApiImplicitParam(name = "hName",value = "栏圈名称"),
            @ApiImplicitParam(name = "hMax",value = "栏圈容量"),
            @ApiImplicitParam(name = "fhName",value = "栏舍名称"),
            @ApiImplicitParam(name = "hEnable",value = "是否可用")
    })
    @GetMapping
    public Result selectAll(Integer pageNum, Integer pageSize,String hName,Integer hMax,String fhName,String hEnable){
        return Result.success(iHurdlesExtService.selectAll(pageNum,pageSize,hName,hMax,fhName,hEnable));
    }

    @PutMapping("{hId}/{hEnable}")
    public  Result updateEnableById(@PathVariable String hId,@PathVariable String hEnable){
        iHurdlesExtService.updateEnable(hId,hEnable);
        return Result.success();
    }


        @DeleteMapping("deleteById/{hId}")
    public Result delete(  @PathVariable String hId){
            iHurdlesExtService.deleteById(hId);
            return Result.success("删除成功");
        }
        @DeleteMapping("deleteByIdAll")
    public Result deleteByBatch(List<String> list){
            return Result.success("删除成功");
        }

        @PutMapping
    public Result updateEnableBatch(@RequestBody List<Map<String,String>> mapList){
        mapList.forEach(e->{
            e.forEach((k,v)-> System.out.println("k = " + k+"               v="+v));
        });
            iHurdlesExtService.updateEnableBatch(mapList);
        return Result.success("批量处理成功");
        }

        @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ManagerHurdlesExt m){
            System.out.println("m = " + m);
        iHurdlesExtService.saveOrUpdate(m);
        return Result.success();
        }



}
